const {selectLotteryNums,getLotteryData} = require('./selectLottery')
const schedule = require('./schedule')
const dingtalkPush = require('../dingtalkPush/index')

// 推送彩票机选
function sendLottery(company, type,to) {
  let lotteryNums = selectLotteryNums(company, type)
  const msg = {
    1: `福利彩票-双色球机选: ${lotteryNums}`,
    2: `体育彩票-大乐透机选: ${lotteryNums}`,
  }
    dingtalkPush.sendMsg(to,msg[company])
}

// 推送开奖结果
async function sendLotteryRes(type, to) {
  await getLotteryData(type).then(res => {
    const msg = {
      1: `福利彩票-双色球最新一期开奖结果: ${res[0].join(', ')}  |  ${res[1].join(', ')}`,
      2: `体育彩票-大乐透最新一期开奖结果: ${res[0].join(', ')}  |  ${res[1].join(', ')}`,
    }
    dingtalkPush.sendMsg(to,msg[type])
  })
}

function setSchedule() {
  schedule.setSchedule(...arguments)
}

module.exports = {
  sendLottery,
  sendLotteryRes,
  setSchedule
}
